<?
   require("../configuracion.php");
   $idSysSection = $sectionRepOperacion;
   require("../application-top.php");
?>
<html>
<head>
  <title><?= $instanciaECRM ?></title>
  <link rel="stylesheet" href="../styles/style.css" type="text/css">

<?
	
	$fecha = split("/",date("d/m/Y"));

	$queryExport = "SELECT  * FROM  SegmPACMEDREP; ";
	$filename = "pacmedrep_";
	
	$nomSegmento = $filename.$fecha[2].$fecha[1].$fecha[0];
	  
	//Comenzamos a enviar
	$file = $nomSegmento . ".xls";
	$out = fopen("xls/" . $file, "w");
	$resExport = mssql_query ($queryExport);
	while($fld = mssql_fetch_field($resExport)){
		fwrite($out, $fld->name . chr(9));
	}
	fwrite($out, chr(13) . chr(10));
	while ($row = mssql_fetch_row($resExport)){
		foreach ($row as $val) {
			fwrite($out, $val . chr(9));
		}
		fwrite($out, chr(13) . chr(10));
	}
	fclose($out);
	
	$url = substr($_SERVER['PHP_SELF'], 0, strrpos ($_SERVER['PHP_SELF'], "/")) . "/xls/" . $file;
	  
	echo "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=".$url."'>";

?>



    

</head>

<body leftmargin="0" class="mainBackground" topmargin="0" marginwidth="0" marginheight="0">
<table width="100" border="0" cellpadding="0" cellspacing="0">
  <tr><td><img src="../images/headerBar.gif" width="590" height="60" alt=""></td></tr>
  <tr>
    <td><table width="800" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td bgcolor="#FFFFFF" valign="top" height="400">

<table border="0" cellpadding="5" cellspacing="0" width="750">
  <tr><td colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td colspan="2"><img src="../images/spacer.gif" height="10" width="1" alt=""></td></tr><tr>
                        <td><strong class="pageTitle">Reportes</strong><br><strong class="pageSubtitle">Reportes Desempe&ntilde;o</strong></td>
                      <td align="right"><a href="http://www.cacto.com/" target="_blank"><img src="../images/trademarkCacto.gif" alt="Cacto" border="0"></a><br><strong class="systemtitle"><?= $instanciaECRM ?></strong><br>Perfil <strong><?= $PerfilUsuario ?></td></tr>
  </table></td></tr>
  <tr>
  <td valign="top" width="100%">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr><td colspan="2">
        <table border="0" cellpadding="5" cellspacing="1" class="mainTableBG">
          <tr class="answerCellBG">
            <td><img src="../images/icArrowGo.gif" height="13" width="13" alt=""></td>
            <td><a href="javascript:history.back();" target="content">Regresar</a></td>
          </tr>
        </table>
      </td></tr>
      <tr><td colspan="2"><img src="../images/spacer.gif" height="10" width="1" alt=""></td></tr>
    </table>

		<br>
		 <strong class="systemtitle">Reporte de Pacientes, M&eacute;dicos y Repres en <?= $eCRMprogram ?></strong><br><br>
		El reporte ha sido generado en un archivo de MS Excel.<br>
		<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#666666">Si la descarga 
                  del archivo no comienza en unos segundos, haga <a href="xls/<?= $file ?>"><strong>click aqu&iacute;</strong></a> 
                  para descargarlo.</font> </td>
  </tr>
</table>
          
          </td>
        </tr>
      </table></td>
  </tr>
</table>

<br>
<br>
<br>
<table width="750" border="0">
  <tr>
    <td align="right"><span class="copyright"><?= $copyright ?></span></td>
  </tr>
</table>
</body>
</html>
